/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.mse.camel.client.posterboard.posterboard.impl;

import edu.mse.camel.client.posterboard.posterboard.*;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;

import org.eclipse.emf.ecore.impl.EFactoryImpl;

import org.eclipse.emf.ecore.plugin.EcorePlugin;

import org.eclipse.swt.graphics.RGB;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model <b>Factory</b>.
 * <!-- end-user-doc -->
 * @generated
 */
public class PosterboardFactoryImpl extends EFactoryImpl implements PosterboardFactory {
	/**
	 * Creates the default factory implementation.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public static PosterboardFactory init() {
		try {
			PosterboardFactory thePosterboardFactory = (PosterboardFactory)EPackage.Registry.INSTANCE.getEFactory("http://edu.mse.camel.posterboard"); 
			if (thePosterboardFactory != null) {
				return thePosterboardFactory;
			}
		}
		catch (Exception exception) {
			EcorePlugin.INSTANCE.log(exception);
		}
		return new PosterboardFactoryImpl();
	}

	/**
	 * Creates an instance of the factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PosterboardFactoryImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EObject create(EClass eClass) {
		switch (eClass.getClassifierID()) {
			case PosterboardPackage.POSTERBOARD: return createPosterboard();
			case PosterboardPackage.PB_DIAGRAM: return createPBDiagram();
			default:
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object createFromString(EDataType eDataType, String initialValue) {
		switch (eDataType.getClassifierID()) {
			case PosterboardPackage.RGB:
				return createRGBFromString(eDataType, initialValue);
			case PosterboardPackage.DIMENSION:
				return createDimensionFromString(eDataType, initialValue);
			case PosterboardPackage.POINT:
				return createPointFromString(eDataType, initialValue);
			default:
				throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String convertToString(EDataType eDataType, Object instanceValue) {
		switch (eDataType.getClassifierID()) {
			case PosterboardPackage.RGB:
				return convertRGBToString(eDataType, instanceValue);
			case PosterboardPackage.DIMENSION:
				return convertDimensionToString(eDataType, instanceValue);
			case PosterboardPackage.POINT:
				return convertPointToString(eDataType, instanceValue);
			default:
				throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Posterboard createPosterboard() {
		PosterboardImpl posterboard = new PosterboardImpl();
		return posterboard;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PBDiagram createPBDiagram() {
		PBDiagramImpl pbDiagram = new PBDiagramImpl();
		return pbDiagram;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public RGB createRGBFromString(EDataType eDataType, String initialValue) {
		//return (RGB)super.createFromString(eDataType, initialValue);
		if (initialValue == null) return null;
		java.util.StringTokenizer st = new java.util.StringTokenizer(initialValue,":");
		return new RGB(new Integer(st.nextToken()).intValue(),new Integer(st.nextToken()).intValue(),new Integer(st.nextToken()).intValue());
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String convertRGBToString(EDataType eDataType, Object instanceValue) {
		//return super.convertToString(eDataType, instanceValue);
		if (instanceValue == null) return null;

		return ""+ ((RGB) (instanceValue)).red+":"+((RGB) (instanceValue)).green+":"+((RGB) (instanceValue)).blue;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT 
	 */
	public Point createPointFromString(EDataType eDataType, String initialValue) {
		//return (Point)super.createFromString(eDataType, initialValue);
		if (initialValue == null) return null;
		java.util.StringTokenizer st = new java.util.StringTokenizer(initialValue,":");
		return new Point(new Double(st.nextToken()).doubleValue(),new Double(st.nextToken()).doubleValue());
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String convertPointToString(EDataType eDataType, Object instanceValue) {
		//return super.convertToString(eDataType, instanceValue);
		if (instanceValue == null) return null;
		
		return ""+ ((Point) (instanceValue)).x+":"+((Point) (instanceValue)).y;
		
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public Dimension createDimensionFromString(EDataType eDataType, String initialValue) {
		//return (Dimension)super.createFromString(eDataType, initialValue);
		if (initialValue == null) return null;
		java.util.StringTokenizer st = new java.util.StringTokenizer(initialValue,":");
		return new Dimension(new Integer(st.nextToken()).intValue(),new Integer(st.nextToken()).intValue());
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String convertDimensionToString(EDataType eDataType, Object instanceValue) {
		//return super.convertToString(eDataType, instanceValue);
		if (instanceValue == null) return null;
		
		return ""+ ((Dimension) (instanceValue)).width+":"+((Dimension) (instanceValue)).height;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PosterboardPackage getPosterboardPackage() {
		return (PosterboardPackage)getEPackage();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @deprecated
	 * @generated
	 */
	@Deprecated
	public static PosterboardPackage getPackage() {
		return PosterboardPackage.eINSTANCE;
	}

} //PosterboardFactoryImpl
